//
//  RMLMainController.swift
//  weibo
//
//  Created by blue on 16/4/18.
//  Copyright © 2016年 blue. All rights reserved.
//

import UIKit

class RMLMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
   
    //初始化tabbar
        let tabbar = RMLTabBar()
        
        tabbar.delegate = self
        
        //通过kvc,把新建的tabbar赋值给系统的tabBar
        setValue(tabbar, forKey: "tabBar")
    
        
    //添加子控制器
        addChildViewController(RMLHomeController(), imgName: "tabbar_home", title: "首页")
        addChildViewController(RMLDicoverController(), imgName: "tabbar_discover", title: "发现")
        addChildViewController(RMLMessageController(), imgName: "tabbar_message_center", title: "消息")
        addChildViewController(RMLProfileController(), imgName: "tabbar_profile", title: "我的")
    }

//添加子控制器方法
    func addChildViewController(childController: UIViewController, imgName: String, title: String) {
        
     //设置图片
        childController.tabBarItem.image = UIImage(named: imgName)
        
    //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
    //设置title
        childController.title = title
    //添加子控制器
        addChildViewController(UINavigationController(rootViewController: childController))
    }

}

extension RMLMainController:RMLTabBarDelegate{

    func compButtonClick() {
        print("按钮被点击了")
    }
    
}
